<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of QueryReplyDao
 *
 * @author lzx
 */
require_once BaseUtil::getModulePath('base').'/models/BaseDao.php';

class QueryReplyDao extends BaseDao{
	
    //put your code here
    protected $_name;
    
    public function _setup(){
        $this->_name = $this->prefix().'query_replies';
        parent::_setup();
    }

    public function updateQueryReply($data,$id){
         $where = $this->db_w->quoteInto('id = ?', $id);
         $this->updateData($data,$where);
    }
    
    public function getQueryReply($queryId){
        $select = $this->db_r->select();
        $select->from($this->_name,array('reply_id','content','created'));
        $select->where('query_replies.query_id=?',$queryId);
        $select->where('query_replies.is_delete=?',0);
        $select->order(array('query_replies.created DESC'));
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result;
    }
    
    public function getReplyInfoByQueryId($queryId){
        $select = $this->db_r->select();
        $select->from($this->_name,array('id','query_id','reply_id','content','modified','created'));        
        $select->join('admins','admins.id=query_replies.reply_id',array("id","username"));
        $select->where('query_replies.query_id=?',$queryId);
        $select->where('query_replies.is_delete=?',0);
        $select->order('query_replies.created DESC');
        $select->limit(1);
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result[0];
    }
    
    public function deleteQueryReply($queryId){
        $isDel = array("is_delete"=>1);
        $where =  $this->db_w->quoteInto('query_id = ?', $queryId);
        $this->updateData($isDel, $where);
    }


}
?>
